import {requestService} from '/src/utils/request'

// 登录方法
export function login(username, password) {
    const data = {
        username,
        password
    }
    return requestService({
        url: '/xiaozhen-sso/sysLogin/doLogin',
        method: 'post',
        data: data,
        transformRequest: [function (data) {
            let ret = ''
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }]
    })
}

//获取个人信息（登录权限验证）
export function getInfo() {
    return requestService({
        url: '/xiaozhen-system/sysUser/getInfo',
        method: 'get'
    })
}

// 获取路由
export function getRouters() {
    return requestService({
        url: '/xiaozhen-system/sysMenu/getRouters',
        method: 'get'
    })
}

//退出登录
export function logout() {
    return requestService({
        url: '/xiaozhen-sso/sysLogin/logout',
        method: 'post'
    })
}

//校验token
export function checkToken(token) {
    const data = {
        token
    }
    return requestService({
        url: '/xiaozhen-sso/sysLogin/checkToken',
        method: 'post',
        data: data,
        transformRequest: [function (data) {
            let ret = ''
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }]
    })
}
